package tree.递归;

import po.TreeNode;

/**
 * @author songZiHao
 * @version 1.0.0
 * @ClassName 单值二叉树965.java
 * @Description https://leetcode-cn.com/problems/univalued-binary-tree/
 * @createTime 2021年08月10日 19:08:00
 */
public class 单值二叉树965 {
	public boolean isUnivalTree(TreeNode root) {
		int num=root.val;
		return dfs(root,num);
	}

	private boolean dfs(TreeNode root, int num) {
		if (root == null) {
			return true;
		}
		if (root.val != num) {
			return false;
		}
		return dfs(root.left,num)&&dfs(root.right,num);
	}
}
